package com.dfbz.controller;

import com.dfbz.service.HomeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

@WebServlet("/home/*")
public class homeServlet<HashMap> extends baseServlet {
    /**
     * 渲染主页的全部数据
     * @param request
     * @param response
     *
     */
    private HomeService homeService=new HomeService();
    public void findAlldata(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查询 今日注册用户、新发布文章、新发布会议等
        Map<String,Object> countData = homeService.findCurData();
        //查询近 7 日新注册用户、新发布文章、新发布会议
        List<Map<String,Object>> detailData = homeService.findSevenData();

        //转换为集合方式便于前端输出
        List<List> countList = new ArrayList<>();
        for (Map<String,Object> map : detailData) {
            List temp = new ArrayList();

            for (Map.Entry<String, Object> entry : map.entrySet()) {
                temp.add(entry.getValue());
            }
            countList.add(temp);

        }
        request.setAttribute("homeCount",countData);
        request.setAttribute("detail",countList);

        request.getRequestDispatcher("/html/home.jsp").forward(request,response);

    }
}
